package com.aixin.csopequity.utils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class Util {

    public static String getUUID(){
       return UUID.randomUUID().toString().replace("-","").toUpperCase();
    }

    public static String getNowDate(){
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :HH:mm:ss");
        return dateFormat.format(date);

    }


    public  static <T,S extends T> T getFatherClass(S classObject)  throws Exception{
        Class objectClass= classObject.getClass();
        Class father=objectClass.getSuperclass();
        Field[] fields = objectClass.getDeclaredFields();
        for (Field field : fields) {
           System.out.println(field.getGenericType());
           System.out.println(father.getName());

            if (field.getGenericType().toString().equals(father.getName())){
                Method m=father.getMethod(getMethodName(field.getName()));
                return   (T)m.invoke(objectClass);
            }
        }
       return  null;
    }

    private static String getMethodName(String fildeName) {
                 byte[] items = fildeName.getBytes();
               items[0] = (byte) ((char) items[0] - 'a' + 'A');
               return new String(items);
             }
}
